package org.zebra.common.util;

import cn.hutool.extra.servlet.ServletUtil;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

/**
 * @author zhanghongbin
 */
public class NetPlusUtil extends cn.hutool.core.net.NetUtil {

    public static final String LOCAL_IPV6 = "0:0:0:0:0:0:0:1";

    /**
     * 判定是否为内网IP<br>
     * 私有IP：A类 10.0.0.0-10.255.255.255 B类 172.16.0.0-172.31.255.255 C类 192.168.0.0-192.168.255.255 当然，还有127这个网段是环回地址
     *
     * @return 是否为内网IP
     */
    public static Boolean isInnerIP() {
        String ip = ServletUtil.getClientIP(
                ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
        if (ip.equals(LOCAL_IPV6)) {
            return true;
        }
        return isInnerIP(ip);
    }
}
